package com.bop.dehong.center.adapter;

import com.base.dehong.base.AdapterBase;
import com.base.dehong.util.DateUtil;
import com.base.dehong.util.StringUtils;
import com.bop.dehong.R;
import com.bop.dehong.info.TradingInfo;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

/**
 * 交易记录
 * @author Tangwenhan
 *2015-11-17下午2:42:07
 */
public class TransactionRecordsAdapter extends AdapterBase<TradingInfo>{

	public TransactionRecordsAdapter(Activity context) {
		super(context);
		// TODO Auto-generated constructor stub
	}

	@Override
	public View getView(int arg0, View convertView, ViewGroup arg2) {
		ViewHolder holder = null;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = LayoutInflater.from(mContext).inflate(R.layout.item_transaction_records_list, null);
			holder.timeTv = getView(convertView, R.id.time);
			holder.typeTv = getView(convertView, R.id.type);
			holder.incomeAndPayTv = getView(convertView, R.id.income_and_pay);
			holder.balanceTv = getView(convertView, R.id.balance);
			
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		TradingInfo info = get(arg0);
		long time = Long.valueOf(info.time+"000");
		String date = DateUtil.getDateTime(time);
		holder.timeTv.setText(date);
		holder.typeTv.setText(info.typename);
		holder.incomeAndPayTv.setText(StringUtils.getThousandFormatValue(info.operation) + "元");
		holder.balanceTv.setText(StringUtils.getThousandFormatValue(info.available_funds) + "元");
		//记住，收支和余额后面要加“元”
		return convertView;
	}
	
	private class ViewHolder {
		//时间
		private TextView timeTv;
		//交易类型
		private TextView typeTv;
		//收支
		private TextView incomeAndPayTv;
		//余额
		private TextView balanceTv;
		
	}

}

